﻿using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using ComputerEngine;
using EngineAdmin;
using GalaSoft.MvvmLight;

namespace DaphneControls.ViewModel
{
    /// <summary>
    /// Engine General Configuration View Model
    /// </summary>
    public class EngineConfigurationVM : ViewModelBase
    {
        // Do we need as an attribute?
        //private EngineConfig _config;

        private Dictionary<eEngineType, string> _engineTypes = new Dictionary<eEngineType, string>()
        {
            { eEngineType.Internal, "Internal" },
            { eEngineType.CheckersBoard, "CheckersBoard" }
        };

        /// <summary>
        /// Initializes a new instance of the EngineConfigurationVM class.
        /// </summary>
        public EngineConfigurationVM(EngineConfig config)
        {
            InternalEngineVM = new InternalEngineSettingsVM(config.InternalEngineSettings);
            PrepareListOfEngineTypes();
            SelectedEngineType = EngineTypes.FirstOrDefault(i => i.EngineType == eEngineType.Internal);
        }

        #region Binding Properties

        public InternalEngineSettingsVM InternalEngineVM
        { get; set; }

        public List<EngineTypeRec> EngineTypes
        { get; set; }

        public EngineTypeRec SelectedEngineType
        { get; set; }

        #endregion

        /// <summary>
        /// Prepares the list of engine types for binding
        /// </summary>
        private void PrepareListOfEngineTypes() {
            EngineTypes = new List<EngineTypeRec>();
            EngineTypes.Add(new EngineTypeRec(0, eEngineType.Internal, _engineTypes[eEngineType.Internal]));            
            EngineTypes.Add(new EngineTypeRec(1, eEngineType.CheckersBoard, _engineTypes[eEngineType.CheckersBoard]));            
        }


        /// <summary>
        /// Engine Type Record Class
        /// </summary>
        public class EngineTypeRec
        {
            public EngineTypeRec(int key, eEngineType type, string title)
            {
                Key = key;
                EngineType = type;
                Title = title;
            }

            public int Key
            { get; set; }

            public eEngineType EngineType
            { get; set; }

            public string Title
            { get; set; }

            public override string ToString()
            {
                return Title;
            }
        }
    }
}